#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
int GetOne(int n)
{
    int count = 0;
    while (n)
    {
        if (n % 2 == 1)
        {
            count++;
        }
        n /= 2;
    }
    return count;
}
int* countBits(int n, int* returnSize)
{
    int* arr = (int*)malloc(sizeof(int) * (n + 1));
    for (int i = 0; i <= n; i++)
    {
        arr[i] = GetOne(i);
    }
    *returnSize = n + 1;
    return arr;
}
int main()
{
    int n = 5;
    int sz = 0;
    int* ret = countBits(n, &sz);
    for (int i = 0; i < sz; i++)
    {
        printf("%d ", ret[i]);
    }
    free(ret);
    return 0;
}